package com.fanqi.ipcapp.comparable;

import androidx.annotation.NonNull;

import java.util.ArrayList;
import java.util.Objects;

/**
 * Created by fanqi on 2020/6/11.
 * Description:用于复习comparable 和comparator的排序
 * Comparable，针对类内进行排序的算法
 */
public class Student implements Comparable<Student> {
    private int age;
    private String name;

    public Student(int i, String s) {
        this.age = i;
        this.name = s;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age &&
                Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(age, name);
    }

    @Override
    public int compareTo(Student o) {
//        return this.age - o.age;
        System.out.format("return=%d", +o.age - this.age);
        return o.age - this.age;

//        if (this.age > o.age) {
//            return 1;
//        } else if (this.age < o.age) {
//            return -1;
//        }
////        else {
////            if (this.name.length() > o.name.length()) {
////                return 1;
////            }else if
////
////        }
//        return 0;
    }

    @NonNull
    @Override
    public String toString() {
        return "student{age=" + this.age + "  name=" + this.name + "}";
    }
}
